/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jsf.session;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jpa.entities.Topic;

/**
 *
 * @author KenShin
 */
@Stateless
public class TopicFacade extends AbstractFacade<Topic> {
    @PersistenceContext(unitName = "SupportiveLearning-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public TopicFacade() {
        super(Topic.class);
    }
//    public Topic getTopicFromId(int topicId)
//    {
//        try
//        {
//        Query query = em.createQuery("SELECT t FROM Topic t WHERE t.topicId = :topicId");
//        query.setParameter("topicId", topicId);
//        return (Topic)query.getSingleResult();
////            Topic test = new Topic();
////            test.setTopicId(topicId);
////            test.setTopicName("Topic 1");
////            return test;
//        }catch(Exception ex)
//        {
//        ex.printStackTrace();
//        }
//        return null;
//    }
    public Topic getListTopicFromId(int topicId)
    {
        Query query = em.createNamedQuery("Topic.findByTopicId");
        query.setParameter("tId", topicId);
        return (Topic)query.getResultList();
    }
}
